package bb.lanxing.activity.routebook;

import static bb.lanxing.model.database.RouteBook.TYPE_IMPORT;

import androidx.annotation.NonNull;
import java.util.List;

import org.osmdroid.views.overlay.Marker;

import com.baidu.mapapi.model.LatLng;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.utils.Utils;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.FragmentActivity;

import bb.lanxing.App;
import bb.lanxing.R;
import bb.lanxing.activity.base.BaseActivity;
import bb.lanxing.activity.sport.SportActivity;
import bb.lanxing.common.config.Constants;
import bb.lanxing.fragment.BaiduMapFragment;
import bb.lanxing.fragment.base.BaseMapFragment;
import bb.lanxing.manager.SharedManager;
import bb.lanxing.manager.TWatchManager;
import bb.lanxing.model.data.IBasePOI;
import bb.lanxing.model.database.RouteBook;
import bb.lanxing.model.database.RouteBookPoint;
import bb.lanxing.model.database.RouteSlope;
import bb.lanxing.mvp.presetner.RouteBookDetailPresenterImpl;
import bb.lanxing.mvp.presetner.i.IRouteDetailPresenter;
import bb.lanxing.mvp.view.i.IRouteDetailView;
import bb.lanxing.util.BiCiCoorConverter;
import bb.lanxing.util.CommonUtil;
import bb.lanxing.util.MapUtil;
import bb.lanxing.util.RxPermissionUtil;
import bb.lanxing.util.UserAvatarUtil;
import bb.lanxing.util.map.MapConfigs;
import bb.lanxing.util.map.MapDrawSupport;
import bb.lanxing.util.map.MapTileChooseUtils;
import bb.lanxing.util.map.MapToolBox;
import bb.lanxing.util.map.MapViewUtil;
import bb.lanxing.util.route.RouteAltitudeChartHelper;
import bb.lanxing.util.ui.AnimationUtil;
import bb.lanxing.view.BiciAlertDialogBuilder;
import bb.lanxing.view.MarkerInfoView;
import gov.nist.core.Separators;

public class RouteBookDetailMapActivity extends BaseActivity
        implements IRouteDetailView, View.OnClickListener, MapDrawSupport {
    private static final String TAG = "RouteDetailMapActivity";
    private LineChart altitudeChart;
    private TextView altitudeChartIcon;
    private ViewGroup altitudeLayout;
    private Object altitudeMarker;
    private TextView chartDetailView;
    private RouteAltitudeChartHelper chartHelper;
    private RelativeLayout contentView;
    private double disSum;
    private TextView distanceView;
    private MenuItem editMenu;
    private TextView idView;
    private BaseMapFragment.InitListener initListener;
    private LatLng lastDisPoint;
    private RouteBook routeBook;
    private ImageView lushuIcon;
    private TextView lushuTitleView;
    private TextView mapChangeBtn;
    private FrameLayout mapContainer;
    private BaseMapFragment mapFragment;
    private MapTileChooseUtils mapTileChooser;
    private MapToolBox mapToolBox;
    private MarkerInfoView markerInfoView;
    private View measureInfoPanel;
    private TextView measureInfoText;
    private View quitMeasureLayout;
    private IRouteDetailPresenter routeDetailPresenter;
    private View titleContainer;
    private TextView toolBoxBtn;
    private TextView usernameView;
    private ImageButton zoomIn;
    private ImageButton zoomOut;
    private boolean isMapReady = false;
    private boolean altitudeOpen = false;
    private boolean distanceOpen = false;
    private boolean altitudeChartOpen = false;
    private long mapCreateTime = 0;
    private long afterDrawLineTime = 0;

    @Override
    public FragmentActivity getActivity() {
        return this;
    }

    @Override
    public void switchMapLocationMode(int mode) {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_route_detail_multi_map);
        bindView(getWindow().getDecorView());
        setupActionBar(true);
        this.zoomIn.setOnClickListener(this);
        this.zoomOut.setOnClickListener(this);
        this.chartDetailView.setOnClickListener(this);
        initView();
    }

    private void initView() {
        setTitle(R.string.lushu_info_title);
        LatLng earth2Baidu = BiCiCoorConverter.earth2Baidu(MapConfigs.getNotNullLastLocation());
        this.mapFragment =
                BaiduMapFragment.newInstance(earth2Baidu.latitude, earth2Baidu.longitude, false, 17.0f, 1, 0);
        this.mapTileChooser = new MapTileChooseUtils(this.mapChangeBtn, this.contentView, this.mapFragment, 0,
                new MapTileChooseUtils.MapTileChangedListener() {
                    @Override
                    public void workoutMapIdChangge(long workoutId, int mapId) {
                    }

                    @Override
                    public boolean beforeChange() {
                        if (isMapReady) {
                            resetMapData();
                        }
                        return isMapReady;
                    }

                    @Override
                    public void afterChanged(BaseMapFragment newMapFragment, int newType) {
                        if (newMapFragment == null || newMapFragment.equals(mapFragment)) {
                            return;
                        }
                        mapFragment = newMapFragment;
                        initMapListener();
                        isMapReady = false;
                        getSupportFragmentManager().beginTransaction().replace(R.id.map_container, mapFragment)
                                .commit();
                    }
                });
        MapToolBox mapToolBox = new MapToolBox(this.toolBoxBtn, this.contentView, new MapToolBox.ToolClickListener() {
            @Override
            public void onSosClick() {
            }

            @Override
            public void onAltitudeClick() {
                measureAltitude();
            }

            @Override
            public void onDistanceClick() {
                measureDistance();
            }
        });
        this.mapToolBox = mapToolBox;
        mapToolBox.setShowSos(false);
        this.initListener = fragment -> {
            isMapReady = true;
            if (!zoomIn.isEnabled() && mapFragment.getZoomLevel() < mapFragment.getMaxOrMinZoom(true)) {
                zoomIn.setEnabled(true);
            }
            if (!zoomOut.isEnabled() && mapFragment.getZoomLevel() > mapFragment.getMaxOrMinZoom(false)) {
                zoomOut.setEnabled(true);
            }
            mapFragment.postDelayed(() -> {
                mapCreateTime = System.currentTimeMillis();
                Log.e(TWatchManager.WORKOUT_START, "timestamp == " + mapCreateTime);
                mapFragment.drawLushu(routeBook, Constants.LUSHU_LINE_COLOR, true);
                afterDrawLineTime = System.currentTimeMillis();
                ((TextView) findViewById(R.id.time_last))
                        .setText(getString(R.string.load_polyline_spent) + (afterDrawLineTime - mapCreateTime) + "ms");
            }, 200L);
        };
        getSupportFragmentManager().beginTransaction().add(R.id.map_container, this.mapFragment).commit();
        this.measureInfoPanel.setOnTouchListener((v, event) -> true);
    }

    @Override
    public void onResume() {
        super.onResume();
        checkLocationPermission();
    }

    public void initMap() {
        long longExtra = getIntent().getLongExtra(SportActivity.EXTRA_LUSHU_ID, -1L);
        RouteBookDetailPresenterImpl routeBookDetailPresenterImpl = new RouteBookDetailPresenterImpl(this);
        this.routeDetailPresenter = routeBookDetailPresenterImpl;
        routeBookDetailPresenterImpl.loadRoute(longExtra);
        this.chartHelper = new RouteAltitudeChartHelper(this.altitudeChart, false, 4, altitudePoint -> {
            LatLng earth2Common;
            LatLng latLng = altitudePoint.getLatLng();
            if (mapFragment instanceof BaiduMapFragment) {
                earth2Common = BiCiCoorConverter.earth2Baidu(latLng);
            } else {
                earth2Common = BiCiCoorConverter.earth2Common(latLng);
            }
            View inflate = LayoutInflater.from(getActivity()).inflate(R.layout.map_sport_altitude_info, null);
            ((TextView) inflate.findViewById(R.id.altitudeMarkerText))
                    .setText(MapUtil.formatAltitude(altitudePoint.getAltitude()));
            Object altitudeMarker = getAltitudeMarker();
            if (altitudeMarker != null) {
                mapFragment.removeOverlay(altitudeMarker, 0);
            }
            setAltitudeMarker(
                    mapFragment.drawMarker(BaseMapFragment.OVERLAY_TYPE_NONE, earth2Common, inflate, 0.5f, 0.907f));
            switchMapLocationMode(1);
            mapFragment.moveTo(earth2Common.latitude, earth2Common.longitude);
        });
    }

    private void checkLocationPermission() {
        if (RxPermissionUtil.getInstance().checkPermission(this, RxPermissionUtil.getLocationStoragePermission())) {
            initMap();
        } else {
            showLocationPermissionDialog();
        }
    }

    private void showLocationPermissionDialog() {
        new BiciAlertDialogBuilder(this).setTitle(getString(R.string.permission_request_permission_tips))
                .setMessage(getResources().getString(R.string.permission_lushu_need_location)).setCancelable(true)
                .setPositiveButton(R.string.dialog_btn_ok, (dialogInterface, i) -> requestLocationPermission())
                .setNegativeButton(R.string.skip, (dialog, which) -> {
                }).create().show();
    }

    public void requestLocationPermission() {
        RxPermissionUtil.getInstance().setPermissions(RxPermissionUtil.getLocationStoragePermission())
                .permissionRequestEachCombined(this, new RxPermissionUtil.PermissionCallBack() {

                    @Override
                    public void granted() {
                        initMap();
                    }

                    @Override
                    public void deny() {
                        App.getContext().showMessage(R.string.sport_gps_permission_title);
                    }
                });
    }

    private void initData() {
        if (!this.routeBook.isUploadEnable()) {
            this.lushuIcon.setImageResource(R.drawable.ic_road_book);
        } else if (this.routeBook.getServerType() == 2) {
            this.lushuIcon.setImageResource(R.drawable.ic_default);
        }
        this.lushuTitleView.setText(this.routeBook.getTitle() == null ? "" : this.routeBook.getTitle());
        TextView textView = this.distanceView;
        textView.setText(CommonUtil.getFormatDistance(this.routeBook.getDistance()) + getString(R.string.unit_km));
        if (this.routeBook.getServerId() <= 0) {
            if (this.routeBook.getSourceType() != 2 && this.routeBook.getUserId() == SharedManager.getInstance().getUserId()
                    && this.routeBook.isUploadEnable()) {
                this.idView.setText(R.string.lushu_info_not_upload);
            } else {
                this.idView.setText("");
            }
            this.idView.setOnLongClickListener(null);
        } else {
            TextView textView2 = this.idView;
            textView2.setText(Separators.POUND + this.routeBook.getServerId());
            this.idView.setOnLongClickListener(v -> {
                boolean copyTextToClipBoard = bb.lanxing.util.text.TextUtils.copyTextToClipBoard(v.getContext(),
                        routeBook != null ? String.valueOf(routeBook.getServerId()) : "");
                if (copyTextToClipBoard) {
                    App.getContext().showMessage(R.string.toast_copy_success);
                }
                return copyTextToClipBoard;
            });
        }
        this.usernameView.setText(this.routeBook.getUsername() != null ? this.routeBook.getUsername() : "");
        if (this.routeBook.getUserId() > 0 && this.routeBook.getUserId() != SharedManager.getInstance().getUserId()) {
            this.usernameView.setOnClickListener(v -> {
                UserAvatarUtil userAvatarUtil = UserAvatarUtil.getInstance();
                userAvatarUtil.goToUserInfo(RouteBookDetailMapActivity.this, RouteBookDetailMapActivity.this.routeBook.getUserId());
            });
        }
        MenuItem menuItem = this.editMenu;
        if (menuItem != null) {
            menuItem.setVisible(this.routeBook.getSourceType() == TYPE_IMPORT || this.routeBook.getUserId() == 0
                    || this.routeBook.getUserId() == ((long) SharedManager.getInstance().getUserId()));
        }
    }

    public void initMapListener() {
        BaseMapFragment baseMapFragment = this.mapFragment;
        if (baseMapFragment == null) {
            return;
        }
        baseMapFragment.setInitListener(this.initListener);
        this.mapFragment.setMapViewListener(new BaseMapFragment.MapViewListener<Object, LatLng, Object, Object>() {
            @Override
            public void onDragMap(Object mapView, boolean end) {
            }

            @Override
            public void onMapLongClick(Object mapView, LatLng point) {
            }

            @Override
            public void onPolylineClick(Object polyline) {
            }

            @Override
            public void onMapClick(Object mapView, LatLng point) {
                LatLng common2Earth;
                if (mapFragment instanceof BaiduMapFragment) {
                    common2Earth = BiCiCoorConverter.baidu2Earth(point);
                } else {
                    // TODO: fdl, OsmMapFragment not implemented
                    // common2Earth = mapFragment instanceof OsmMapFragment ? BiCiCoorConverter.common2Earth(point) :
                    // point;
                    common2Earth = point;
                }
                if (!distanceOpen) {
                    if (altitudeOpen) {
                        MapViewUtil.drawAltitude(RouteBookDetailMapActivity.this, point, common2Earth,
                                RouteBookDetailMapActivity.this.measureInfoText);
                    }
                } else {
                    MapViewUtil.drawDistance(RouteBookDetailMapActivity.this, point, common2Earth,
                            RouteBookDetailMapActivity.this.measureInfoText);
                }
                if (altitudeChartOpen) {
                    closeAltitudeChart();
                }
                if (markerInfoView.isShown()) {
                    markerInfoView.hide();
                }
            }

            @Override
            public void onMakerClick(Object marker) {
                Marker marker2;
                Object relatedObject;
                IBasePOI iBasePOI;
                if (marker instanceof com.baidu.mapapi.map.Marker marker3) {
                    if (marker3.getExtraInfo() == null
                            || (iBasePOI = marker3.getExtraInfo().getParcelable("infoPoint")) == null) {
                        return;
                    }
                    if (altitudeChartOpen) {
                        closeAltitudeChart();
                    }
                    markerInfoView.show(iBasePOI);
                    mapFragment.moveTo(marker3.getPosition().latitude, marker3.getPosition().longitude);
                } else if ((marker instanceof Marker)
                        && (relatedObject = (marker2 = (Marker) marker).getRelatedObject()) != null
                        && (relatedObject instanceof IBasePOI)) {
                    if (altitudeChartOpen) {
                        closeAltitudeChart();
                    }
                    markerInfoView.show((IBasePOI) relatedObject);
                    mapFragment.moveTo(marker2.getPosition().getLatitude(), marker2.getPosition().getLongitude());
                }
            }

            @Override
            public void onZoom(float zoom) {
                if (zoomIn.isEnabled()) {
                    if (zoom >= mapFragment.getMaxOrMinZoom(true)) {
                        zoomIn.setEnabled(false);
                    }
                } else if (zoom < mapFragment.getMaxOrMinZoom(true)) {
                    zoomIn.setEnabled(true);
                }
                if (zoomOut.isEnabled()) {
                    if (zoom <= mapFragment.getMaxOrMinZoom(false)) {
                        zoomOut.setEnabled(false);
                    }
                } else if (zoom > mapFragment.getMaxOrMinZoom(false)) {
                    zoomOut.setEnabled(true);
                }
            }
        });
    }

    @Override
    public void onLoadRoute(RouteBook routeBook) {
        this.routeBook = routeBook;
        initData();
        initMapListener();
    }

    @Override
    public void onLoadAltitudePoints(List<RouteBookPoint> lushuPoints, List<Float> distances) {
        this.chartHelper.initChart(lushuPoints, distances);
        AnimationUtil.slideUpShow(this.altitudeLayout, false, null);
    }

    @Override
    public void onLoadAltitudeFailed() {
        this.altitudeChartIcon.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_img_altitude_chart_gray, 0, 0);
        this.altitudeChartOpen = false;
    }

    @Override
    public void onLoadSlopes(List<RouteSlope> routeSlopes) {
        if (routeSlopes != null && !routeSlopes.isEmpty()) {
            this.chartDetailView.setVisibility(View.VISIBLE);
            this.chartHelper.initSlope(routeSlopes, false);
            addSlopeMarker(routeSlopes);
            return;
        }
        this.chartDetailView.setVisibility(View.INVISIBLE);
        BaseMapFragment baseMapFragment = this.mapFragment;
        if (baseMapFragment != null) {
            baseMapFragment.clearOverlay(BaseMapFragment.OVERLAY_TYPE_POI);
        }
    }

    private void addSlopeMarker(List<RouteSlope> routeSlopes) {
        if (this.mapFragment == null) {
            return;
        }
        List<RouteBookPoint> altitudePoints = this.chartHelper.getAltitudePoints();
        TextView textView =
                (TextView) LayoutInflater.from(this).inflate(R.layout.map_marker_slope_route, this.mapContainer, false);
        for (RouteSlope routeSlope : routeSlopes) {
            int sampleEndIndex = routeSlope.getSampleEndIndex() - 1;
            if (sampleEndIndex < 0) {
                sampleEndIndex = 0;
            }
            if (!routeSlope.getLevel().equals("Na")) {
                textView.setText(routeSlope.getLevel());
                LatLng latLng = altitudePoints.get(sampleEndIndex).getLatLng();
                BaseMapFragment baseMapFragment = this.mapFragment;
                if (baseMapFragment instanceof BaiduMapFragment) {
                    latLng = BiCiCoorConverter.earth2Baidu(latLng);
                }
                // TODO: fdl, OsmMapFragment not implemented
                // else if (baseMapFragment instanceof OsmMapFragment) {
                // latLng = BiCiCoorConverter.earth2Common(latLng);
                // }
                this.mapFragment.drawMarker(BaseMapFragment.OVERLAY_TYPE_POI, latLng, textView, 0.5f, 0.5f);
            }
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_route_detail_map, menu);
        MenuItem findItem = menu.findItem(R.id.route_detail_map_edit);
        this.editMenu = findItem;
        RouteBook routeBook = this.routeBook;
        if (routeBook != null) {
            findItem.setVisible(routeBook.getSourceType() == 2 || this.routeBook.getUserId() == 0
                    || this.routeBook.getUserId() == ((long) SharedManager.getInstance().getUserId()));
        }
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (R.id.route_detail_map_edit == item.getItemId()) {
            Intent intent = new Intent(this, RouteBookEditActivity.class);
            intent.putExtra(SportActivity.EXTRA_LUSHU_ID, this.routeBook.getId());
            startActivityForResult(intent, 76);
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.routeDetailPresenter.destroy();
    }

    @Override
    public void onBackPressed() {
        if (this.altitudeChartOpen) {
            closeAltitudeChart();
        } else if (this.markerInfoView.isShown()) {
            this.markerInfoView.hide();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != 0) {
            setResult(resultCode);
        }
        if (resultCode != Constants.RESULT_CODE_LUSHU_EDIT) {
            if (resultCode == Constants.RESULT_CODE_LUSHU_DELETE) {
                finish();
                return;
            }
            return;
        }
        this.routeBook = RouteBook.getById(this.routeBook.getId());
        initData();
        BaseMapFragment baseMapFragment = this.mapFragment;
        if (baseMapFragment == null || !this.isMapReady) {
            return;
        }
        baseMapFragment.clearOverlay(BaseMapFragment.OVERLAY_TYPE_ROAD_BOOK);
        this.mapFragment.drawLushu(this.routeBook, Constants.LUSHU_LINE_COLOR, true);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.altitudeChartIcon) {
            onAltitudeChartClick();
        } else if (id == R.id.mapChangeBtn) {
            this.mapTileChooser.show();
        } else if (id == R.id.map_quit_measure) {
            onQuitMeasureClick();
        } else if (id == R.id.route_chart_detail) {
            startActivity(new Intent(this, RouteBookChartActivity.class).putExtra("route_id", this.routeBook.getServerId()));
        } else if (id == R.id.toolBoxBtn) {
            this.mapToolBox.show();
        } else if (id == R.id.zoomIn) {
            if (this.mapFragment != null) {
                Log.i(TAG, "onClick: zoom in " + this.mapFragment.getZoomLevel());
                this.mapFragment.zoomIn();
            }
        } else if (id == R.id.zoomOut) {
            if (this.mapFragment != null) {
                Log.i(TAG, "onClick: zoom out " + this.mapFragment.getZoomLevel());
                this.mapFragment.zoomOut();
            }
        }
    }

    void onQuitMeasureClick() {
        if (this.altitudeOpen) {
            if (this.mapFragment.clearOverlay(BaseMapFragment.OVERLAY_TYPE_ALTITUDE)) {
                App.getContext().showMessage(R.string.map_clear_altitude_info);
            }
            this.altitudeOpen = false;
        } else if (this.distanceOpen) {
            if (this.mapFragment.clearOverlay(BaseMapFragment.OVERLAY_TYPE_DISTANCE)) {
                App.getContext().showMessage(R.string.map_clear_distance_info);
                this.lastDisPoint = null;
            }
            this.distanceOpen = false;
        }
        AnimationUtil.slideDownHide(this.measureInfoPanel, null);
    }

    void measureAltitude() {
        if (this.altitudeOpen) {
            App.getContext().showMessage(R.string.map_clear_altitude_hint);
            return;
        }
        AnimationUtil.slideUpShow(this.measureInfoPanel, true, null);
        if (this.distanceOpen) {
            if (this.mapFragment.clearOverlay(BaseMapFragment.OVERLAY_TYPE_DISTANCE)) {
                this.lastDisPoint = null;
            }
            this.distanceOpen = false;
        }
        App.getContext().showMessage(R.string.map_click_show_altitude);
        this.measureInfoText.setText(R.string.map_measure_altitude_text);
        this.altitudeOpen = true;
    }

    void measureDistance() {
        if (this.distanceOpen) {
            App.getContext().showMessage(R.string.map_clear_distance_hint);
            return;
        }
        AnimationUtil.slideUpShow(this.measureInfoPanel, true, null);
        if (this.altitudeOpen) {
            this.mapFragment.clearOverlay(BaseMapFragment.OVERLAY_TYPE_ALTITUDE);
            this.altitudeOpen = false;
        }
        App.getContext().showMessage(R.string.map_click_measure_distance);
        this.measureInfoText.setText(R.string.map_measure_distance_text);
        this.distanceOpen = true;
    }

    void onAltitudeChartClick() {
        if (this.altitudeChartOpen) {
            closeAltitudeChart();
        } else {
            showAltitudeChart();
        }
    }

    @Override
    public void exit() {
        finish();
    }

    public void showAltitudeChart() {
        this.altitudeChartOpen = true;
        if (this.markerInfoView.getState() == 1) {
            this.markerInfoView.hide();
        } else if (this.markerInfoView.getState() == 2) {
            MarkerInfoView markerInfoView = this.markerInfoView;
            markerInfoView.changeToHide(markerInfoView.getBigStateHeight());
        }
        this.altitudeChartIcon.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_img_altitude_chart_blue, 0, 0);
        this.routeDetailPresenter.loadRouteAltitude(this.routeBook);
    }

    public void closeAltitudeChart() {
        this.altitudeChartIcon.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_img_altitude_chart_gray, 0, 0);
        AnimationUtil.slideDownHide(this.altitudeLayout, null);
        this.altitudeChartOpen = false;
        Object obj = this.altitudeMarker;
        if (obj != null) {
            this.mapFragment.removeOverlay(obj, 0);
        }
    }

    public void resetMapData() {
        this.mapFragment.clearOverlay(BaseMapFragment.OVERLAY_TYPE_NAV);
        this.disSum = Utils.DOUBLE_EPSILON;
        this.lastDisPoint = null;
        this.altitudeMarker = null;
        if (this.altitudeChartOpen) {
            closeAltitudeChart();
        }
    }

    @Override
    public BaseMapFragment getMapFragment() {
        return this.mapFragment;
    }

    @Override
    public boolean isAltitudeOpen() {
        return this.altitudeOpen;
    }

    @Override
    public LatLng getLastDistancePoint() {
        return this.lastDisPoint;
    }

    @Override
    public void setLastDistancePoint(LatLng lastDistancePoint) {
        this.lastDisPoint = lastDistancePoint;
    }

    @Override
    public double getDistanceSum() {
        return this.disSum;
    }

    @Override
    public void setDistanceSum(double distanceSum) {
        this.disSum = distanceSum;
    }

    @Override
    public Object getAltitudeMarker() {
        return this.altitudeMarker;
    }

    @Override
    public void setAltitudeMarker(Object altitudeMarker) {
        this.altitudeMarker = altitudeMarker;
    }

    private void bindView(View bindSource) {
        this.contentView = bindSource.findViewById(R.id.content_view);
        this.zoomIn = bindSource.findViewById(R.id.zoomIn);
        this.zoomOut = bindSource.findViewById(R.id.zoomOut);
        this.mapContainer = bindSource.findViewById(R.id.map_container);
        this.titleContainer = bindSource.findViewById(R.id.title_container);
        this.lushuIcon = bindSource.findViewById(R.id.lushuIcon);
        this.lushuTitleView = bindSource.findViewById(R.id.lushuTitleView);
        this.distanceView = bindSource.findViewById(R.id.distanceView);
        this.idView = bindSource.findViewById(R.id.idView);
        this.usernameView = bindSource.findViewById(R.id.usernameView);
        this.mapChangeBtn = bindSource.findViewById(R.id.mapChangeBtn);
        this.toolBoxBtn = bindSource.findViewById(R.id.toolBoxBtn);
        this.altitudeChartIcon = bindSource.findViewById(R.id.altitudeChartIcon);
        this.markerInfoView = bindSource.findViewById(R.id.markerInfoView);
        this.chartDetailView = bindSource.findViewById(R.id.route_chart_detail);
        this.altitudeChart = bindSource.findViewById(R.id.altitudeChart);
        this.altitudeLayout = bindSource.findViewById(R.id.altitudeLayout);
        this.measureInfoPanel = bindSource.findViewById(R.id.measure_info_panel);
        this.measureInfoText = bindSource.findViewById(R.id.measure_info_text);
        this.quitMeasureLayout = bindSource.findViewById(R.id.map_quit_measure);
    }
}
